import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/auth/login',
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: '/user/info',
    method: 'get',
    params: { token }
  })
}

export function logout() {
  return request({
    url: '/auth/logout',
    method: 'post'
  })
}

// 获取用户分页列表
export function getUserPage(params) {
  return request({
    url: '/users/page',
    method: 'get',
    params
  })
}

// 获取用户详情
export function getUserById(id) {
  return request({
    url: `/users/${id}`,
    method: 'get'
  })
}

// 添加用户
export function addUser(data) {
  return request({
    url: '/users',
    method: 'post',
    data
  })
}

// 更新用户
export function updateUser(data) {
  return request({
    url: '/users',
    method: 'put',
    data
  })
}

// 删除用户
export function deleteUser(id) {
  return request({
    url: `/users/${id}`,
    method: 'delete'
  })
}

// 批量删除用户
export function batchDeleteUser(ids) {
  return request({
    url: '/users/batch',
    method: 'delete',
    data: ids
  })
}

// 重置密码
export function resetPassword(id) {
  return request({
    url: `/users/${id}/reset-password`,
    method: 'put'
  })
}

// 修改密码
export function changePassword(id, oldPassword, newPassword) {
  return request({
    url: '/users/change-password',
    method: 'put',
    params: {
      id,
      oldPassword,
      newPassword
    }
  })
}

// 修改用户状态
export function changeStatus(id, status) {
  return request({
    url: `/users/${id}/status/${status}`,
    method: 'put'
  })
}

// 获取用户角色ID列表
export function getUserRoleIds(id) {
  return request({
    url: `/users/${id}/roles`,
    method: 'get'
  })
}

// 获取用户权限列表
export function getUserPermissions(id) {
  return request({
    url: `/users/${id}/permissions`,
    method: 'get'
  })
}